import subprocess

def get_connected_devices():
    """
    获取通过 ADB 连接的设备列表（仅 SN）。
    """
    result = subprocess.run(['adb', 'devices'], capture_output=True, text=True)
    devices = []
    for line in result.stdout.splitlines():
        if "List of devices attached" not in line and line.strip():
            device_info = line.split()
            if len(device_info) > 1 and device_info[1] == "device":
                devices.append(device_info[0])
    return devices

def adb_command(sn, command):
    """
    对指定设备执行 ADB 命令。
    """
    subprocess.run(['adb', '-s', sn] + command, text=True)

def uninstall_apps(sn):
    """
    卸载指定的应用列表。
    """
    uninstall_packages = [
        "za.co.fnb.connect.itt",
        "africa.finserve.mkey",
        "com.rahazachumbani.app",
        "com.shopclues",
        "com.asiainno.uplive",
        "video.like",
        "com.ludashi.dualspace",
        "com.cyberlink.youperfect",
        "com.callerscreen.color.phone.ringtone.flash",
        "com.adobe.lrmobile",
        "com.jio.media.ondemand",
        "com.sharekaro.app",
        "id.dana",
        "share.sharekaro.pro",
        "vpn.video.downloader",
    ]
    for package in uninstall_packages:
        print(f"正在卸载应用：{package} (设备：{sn})")
        adb_command(sn, ['uninstall', package])

def modify_device_settings(sn):
    """
    修改设备屏幕超时时间。
    """
    print(f"正在修改设备 {sn} 的屏幕超时时间...")
    adb_command(sn, ['shell', 'settings', 'put', 'system', 'screen_off_timeout', '1800000'])
